//
//  FirstCenterCell.m
//  ProjectA
//
//  Created by lanouhn on 15/5/24.
//  Copyright (c) 2015年 lanouhn. All rights reserved.
//

#import "FirstCenterCell.h"
#import "FirstModel.h"
#import "UIImageView+WebCache.h"

#define padding 5
#define kScreen [UIScreen mainScreen].bounds.size.width
#define CircleWH 20
#define topButtomPadding (cellHeight-10 - CGRectGetHeight(target) - padding * 1.5 - 20) / 2

@interface FirstCenterCell ()

@property (nonatomic ,retain)UIImageView *aImageView;
@property (nonatomic ,retain)UILabel *alable;
@property (nonatomic ,retain)UILabel *clocklable;
//@property (nonatomic ,retain)ContentModel *model;
@property (nonatomic ,retain)UIImageView *clock;
@property (nonatomic ,retain)UIImageView *start;
@property (nonatomic ,retain)UILabel *startlable;
@end
@implementation FirstCenterCell
- (void)dealloc{
    [_aImageView release];
    [_alable release];
    [_clocklable release];
    [_clock release];
    [_start release];
    [_startlable release];
    [super dealloc];
}
- (UIImageView *)aImageView {
    if (!_aImageView) {
        self.aImageView = [[[UIImageView alloc]initWithFrame:CGRectMake(5, 20, 130, 100)]autorelease];
        [self.contentView addSubview:_aImageView];
    }
    return _aImageView ;
}
- (UILabel *)alable {
    if (!_alable) {
        self.alable = [[[UILabel alloc]initWithFrame:CGRectZero]autorelease];
        _alable.numberOfLines = 0;
        _alable.font = [UIFont systemFontOfSize:16];
        [self.contentView addSubview:_alable];
    }
    return _alable ;
}
/*
  kScreen - (CGRectGetMaxX(self.aImageView.frame) + padding * 1.5), 80
 */
- (UIImageView *)clock{
    if (!_clock) {
        self.clock = [[[UIImageView alloc]initWithFrame:CGRectZero]autorelease];
        _clock.alpha = .3;
        [self.contentView addSubview:_clock];
    }
    return _clock ;
}
- (UILabel *)clocklable {
    if (!_clocklable) {
        self.clocklable = [[[UILabel alloc]initWithFrame:CGRectZero]autorelease];
        [self.contentView addSubview:_clocklable];
    }
    return _clocklable ;
}
- (UIImageView *)start{
    if (!_start) {
        self.start = [[[UIImageView alloc]initWithFrame:CGRectZero]autorelease];
        _start.alpha = 0.3;
        [self.contentView addSubview:_start];
    }
    return _start ;

}
- (UILabel *)startlable {
    if (!_startlable) {
        self.startlable = [[[UILabel alloc]initWithFrame:CGRectZero]autorelease];
        [self.contentView addSubview:_startlable];
    }
    return _startlable ;
}
- (void)layoutSubviews {
    [super layoutSubviews];
//    CGFloat cellWidth = self.frame.size.width;
    CGFloat cellHeight = self.frame.size.height ;
    //图片
    self.aImageView.frame = CGRectMake(5, 5, 100, cellHeight-10);
    //titleLabel//
    CGFloat labelWidth = kScreen - (CGRectGetMaxX(self.aImageView.frame) + padding * 1.5) ;
    CGSize size = CGSizeMake( labelWidth, MAXFLOAT);
    CGRect target = [self.alable.text boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin |NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName : _alable.font} context:nil];
    self.alable.frame =  CGRectMake(CGRectGetMaxX(self.aImageView.frame) + padding, topButtomPadding, labelWidth,CGRectGetHeight(target));
    self.clock.frame = CGRectMake(CGRectGetMaxX(self.aImageView.frame) + padding, CGRectGetMaxY(self.alable.frame) + padding * 1.5, CircleWH, CircleWH);
    self.clocklable.frame = CGRectMake(CGRectGetMaxX(self.clock.frame) + padding, CGRectGetMaxY(self.alable.frame) + padding * 1.5, 70, 15);
    self.start.frame = CGRectMake(CGRectGetMaxX(self.clocklable.frame)  , CGRectGetMaxY(self.alable.frame) + padding * 1.5, CircleWH , CircleWH);
    self.startlable.frame = CGRectMake(CGRectGetMaxX(self.start.frame) + padding, CGRectGetMaxY(self.alable.frame) + padding * 1.5,70, 15);
    
}
- (void)cellWithModel:(FirstModel *)contentModel temp:(BOOL)temp{
    [self.aImageView sd_setImageWithURL:[NSURL URLWithString:contentModel.avatar]];//头像
    
    if (contentModel.Num != nil&&temp ==YES) {
        self.clock.image = [UIImage imageNamed:@"icon_time"];
        self.start.image = [UIImage imageNamed:@"icon_num"];
        self.startlable.text = contentModel.Num;
        self.clocklable.text = contentModel.duration;

    } else {
        self.clock.image = [UIImage imageNamed:@"icon_time"];
        self.clocklable.text = contentModel.duration;
    }
 //   self.alable.font = [UIFont systemFontOfSize:16];
    if(contentModel.uesrName != nil){
        self.alable.text = [NSString stringWithFormat:@"【%@】%@",contentModel.uesrName,contentModel.title];
    } else {
      self.alable.text = [NSString stringWithFormat:@"%@",contentModel.title];
    }
    
}
@end
